package com.pan.excep;


import com.pan.entity.Result;
import com.pan.excep.error.AspectException;
import com.pan.excep.error.ServiceException;
import com.pan.tools.ConvertObject;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.annotation.Resource;

//@RestControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(ServiceException.class)
    @ResponseBody
    public Result serviceHandler(ServiceException serviceException){
        Result result = (Result) ConvertObject
                .convertObject(new Result(),serviceException);
        result.setData(serviceException);
        return result;
    }

    @ResponseBody
    @ExceptionHandler(AspectException.class)
    public Result AspectHandler(AspectException aspectException){
        Result result = ConvertObject
                .convertObject(new Result<>(),aspectException)
                .setData(aspectException);
        return result;
    }

}
